package com.skywolf.chem.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skywolf.chem.article.entity.LiveInfo;
import com.skywolf.chem.article.mapper.LiveInfoMapper;
import com.skywolf.chem.article.pojo.LiveQueryParam;
import com.skywolf.chem.article.service.ILiveInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;

/**
 * <p>
 * 直播信息表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-06-09
 */
@Service
public class LiveInfoServiceImpl extends ServiceImpl<LiveInfoMapper, LiveInfo> implements ILiveInfoService {


    @Autowired
    LiveInfoMapper liveInfoMapper;

    @Override
    public IPage<LiveInfo> livePageList(LiveQueryParam queryParam) {
        QueryWrapper<LiveInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted", 0);
        if(queryParam.getVideoType()!=null){
            queryWrapper.eq("video_type", queryParam.getVideoType());
        }
        if(StringUtils.isNotBlank(queryParam.getTitle())){
            queryWrapper.like("video_title", queryParam.getTitle());
        }
        if(StringUtils.isNotBlank(queryParam.getStartTime()) && StringUtils.isNotBlank(queryParam.getEndTime())){
            queryWrapper.between("created_time", queryParam.getStartTime(),queryParam.getEndTime());
        }
        queryWrapper.orderByDesc("created_time");
        return this.page(queryParam.page(), queryWrapper);
    }

    @Override
    public IPage<LiveInfo> reLivePageList(LiveQueryParam queryParam) {
        QueryWrapper<LiveInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted", 0);
        queryWrapper.eq("video_type", queryParam.getVideoType());
        if(StringUtils.isNotBlank(queryParam.getTitle())){
            queryWrapper.like("video_title", queryParam.getTitle());
        }
        if(StringUtils.isNotBlank(queryParam.getStartTime()) && StringUtils.isNotBlank(queryParam.getEndTime())){
            queryWrapper.between("created_time", queryParam.getStartTime(),queryParam.getEndTime());
        }
        return this.page(queryParam.page(), queryWrapper);
    }



}
